Walkthrough 4-6: Implement a RESTful web service

In this walkthrough, you wire the RESTful web service interface up to your back-end logic. You will:

·       Pass an event from one flow to another.

·       Call the backend flows.

·       Create new logic for the nested resource call.

·       Test the web service using Advanced REST Client.

  

Starting file

If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the solutions folder of the student files ZIP located in the Course Resources.

Rename the configuration files

1.     Return to Anypoint Studio.

2.     Right-click american-flights-api.xml in the Package Explorer and select Refactor > Rename.

3.     In the Rename Resource dialog box, set the new name to interface.xml and click OK.

4.     Right-click training4-american-ws.xml and select Refactor > Rename.

5.     In the Rename Resource dialog box, set the new name to implementation.xml and click OK.

 

Use a Flow Reference in the /flights resource

6.     Open interface.xml.

7.     Delete the Transform Message component in the get:/flights flow.

8.     In the Mule Palette, select Core and locate the Components section in the right-side.

  

9.     Drag a Flow Reference component from the Mule Palette and drop it into the process section of the flow.

  

10.  In the Flow Reference properties view, select getFlights for the flow name.

  

11.  Change the display name to getFlights.

Use a Flow Reference in the /flights/{ID} resource

12.  Delete both the Transform Message components in the get:/flights/{ID} flow.

13.  Drag a Flow Reference component from the Mule Palette and drop it into the flow.

14.  In the Flow Reference properties view, select getFlightsByID for the flow name.

   

15.  Change the display name to getFlightsByID.

Test the web service using Advanced REST Client

16.  Save the file to redeploy the project.

Note: If a redeploy does not occur, stop then restart the project.

17.  In Advanced REST Client, make a request to http://localhost:8081/api/flights; you should now get the data for all the flights from the database instead of the sample data.

 

Note: If you use the pre-built Training: American Flights API connector, you must add client_id and client_secret headers with any values.

18.  Make a request to http://localhost:8081/api/flights/3; you should now get the data that flight from the database instead of the sample data.

19.  Return to Anypoint Studio.

20.  Stop the project.



Did you complete the walkthrough?

  Yes, I completed the walkthrough

  No, I did not complete the walkthrough

  I completed part of the walkthrough


Comments and/or feedback